<?php
/**
 * Created by PhpStorm.
 * User: yzh
 * Date: 2019/5/20
 * Time: 10:57
 */

namespace app\api\model;


class PosterUser extends BaseModel
{
    public $autoWriteTimestamp = true;

    public function users(){
        return $this->belongsTo('User','user_id','id')->field('id,nickname,avatar_url');
    }


    /**
     * 添加记录
     * @param $user_id
     * @param $poster
     * @return false|int
     */
    public function addLog($user_id,$poster){
        $data['user_id'] = $user_id;
        $data['poster_id'] = $poster;
        $posterUser = new PosterUser();
        return $posterUser->save($data);
    }

    /**
     * 查询记录
     * @param $user_id
     * @param $poster
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getLog($user_id,$poster){
        return self::where('user_id','=',$user_id)
            ->where('poster_id','=',$poster)
            ->find();
    }

}